<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得表名</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mysql-stat.html">« mysql_stat</a></li>
      <li style="float: right;"><a href="function.mysql-thread-id.html">mysql_thread_id »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mysql.html">MySQL 函数</a></li>
    <li>取得表名</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mysql-tablename" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_tablename</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_tablename</span> &mdash; <span class="dc-title">取得表名</span></p>

 </div>

 <div id="function.mysql-tablename-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.html" class="link">MySQLi</a>
或 <a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a> 扩展来替换之。参见 <a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 
指南来获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li class="member">SQL Query: <code class="literal">SHOW TABLES</code></li>
   </ul>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-tablename-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_tablename</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$i</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   从 <code class="parameter">result</code> 中取得表名。
  </p>
  <p class="para">
   此函数已废弃，推荐使用
   <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> 函数来执行 SQL <code class="literal">SHOW TABLES
   [FROM db_name] [LIKE &#039;pattern&#039;]</code> 替代。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-tablename-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">result</code></dt>

     <dd>

      <p class="para">
       接受 <span class="function"><a href="function.mysql-list-tables.html" class="function">mysql_list_tables()</a></span> 返回的结果指针以及一个整数索引作为参数并返回表名。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">i</code></dt>

     <dd>

      <p class="para">
       The integer index (row/table number)
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-tablename-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回表名 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
  <p class="para">
   Use the <span class="function"><strong>mysql_tablename()</strong></span> function to
   traverse this result pointer, or any function for result tables,
   such as <span class="function"><a href="function.mysql-fetch-array.html" class="function">mysql_fetch_array()</a></span>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mysql-tablename-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table id="function.mysql-tablename.changelog" class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.5.0</td>
       <td>
        <span class="function"><strong>mysql_tablename()</strong></span> 函数已废弃，调用时会抛出
        <strong><code>E_DEPRECATED</code></strong> 级别的错误。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-tablename-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1784">
    <p><strong>示例 #1 <span class="function"><strong>mysql_tablename()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_list_tables</span><span style="color: #007700">(</span><span style="color: #DD0000">"mydb"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$num_rows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$num_rows</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Table:&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysql_tablename</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-tablename-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    The <span class="function"><a href="function.mysql-num-rows.html" class="function">mysql_num_rows()</a></span> function may be used to
    determine the number of tables in the result pointer.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-tablename-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mysql-list-tables.html" class="function" rel="rdfs-seeAlso">mysql_list_tables()</a> - 列出 MySQL 数据库中的表</span></li>
    <li class="member"><span class="function"><a href="function.mysql-field-table.html" class="function" rel="rdfs-seeAlso">mysql_field_table()</a> - 取得指定字段所在的表名</span></li>
    <li class="member"><span class="function"><a href="function.mysql-db-name.html" class="function" rel="rdfs-seeAlso">mysql_db_name()</a> - 取得 mysql_list_dbs 返回的结果数据</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>